{extend name="indexextends"}



{block name="title"}主页管理{/block}

{block name='home'}layui-this{/block}


{block name='nr'}

<blockquote class="layui-elem-quote">欢迎使用Easycms</blockquote>

<div class="layui-row layui-col-space15">




    <div class="layui-col-md6">
        <div class="layui-panel">
            <div style="padding: 30px;">
                    <p style="color: red"><i class="layui-icon" style="color: red">&#xe702;</i>警告：使用Easycms前请先完整的填写配置信息</p>
                    <br>
                    <p>若你的cms系统安装在站点根目录，那么假如你域名为www.aaa.com，如果想选择根目录的www.aaa.com/index.html作为主页路径，那么就填写../</p>
                    <br>
                    <p>此处设置的<span style="color: red">根目录路径</span>，后续发布文章时上传的图片都会保存在根目录下uploadImg文件中</p>
                    <br>
                    <p>主页模板名称默认为<span style="color: red">index.html</span>，如若需要修改，在此处修改名称之后需手动修改<span style="color: red">\cms\public\static\templets</span>目录下的文件名称</p>
                    <br>
                    <p>项目文件夹名称默认为<span style="color: red">cms</span></p>

                <table class="layui-hide" id="test" lay-filter="test"></table>

                <script type="text/html" id="toolbarDemo">
                    <div class="layui-btn-container">
                        <button class="layui-btn layui-btn-sm" lay-event="add">新增配置</button>
                    </div>
                </script>

                <script type="text/html" id="barDemo">
                    <a class="layui-btn layui-btn-xs" lay-event="edit">修改配置</a>
                </script>





                    <div class="layui-form-item">

                            
                            <div class="layui-btn layui-btn-normal"><a href="{:url('admin/home/Preview')}" target="_blank" style="color: white">预览主页</a></div>
                            <div class="layui-btn"><a href="{:url('admin/home/updateHomePage')}" target="_blank" style="color: white">更新主页</a></div>


                    </div>



            </div>
        </div>
    </div>




</div>












{/block}

{block name='js'}

<script>






layui.use('table', function(){
    var table = layui.table;

    table.render({
        elem: '#test'
        ,url:'{:url("admin/home/showConfig")}'
        ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
        ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
            title: '提示'
            ,layEvent: 'LAYTABLE_TIPS'
            ,icon: 'layui-icon-tips'
        }]
        ,title: '用户数据表'
        ,cols: [[
            {field:'homepath', title:'项目路径', width:200, }
            ,{field:'filename', title:'主页模板名称', width:200, }
            ,{field:'projectname', title:'项目文件夹名称', width:250, }
            ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:183}
        ]]
        ,page: true
    });

    //头工具栏事件
    table.on('toolbar(test)', function(obj){
        var checkStatus = table.checkStatus(obj.config.id);
        var data = checkStatus.data //被选中的文章的所有数据内容
        switch(obj.event){
            case 'add'://新增配置
                add();
                break;
        };
    });


    function add(){

        var addHtml = '<form id="form1" class="layui-form" method="post" action="{:url(\'admin/home/addHomeConfig\')}" style="width:460px; margin-top: 20px;">\
                           <div class="layui-form-item">\
                             <label class="layui-form-label"><span style="color: red">*</span>项目路径</label>\
                             <div class="layui-input-block">\
                               <input type="text" name="path" lay-verify="title" autocomplete="off" placeholder="请输入项目路径" class="layui-input">\
                             </div>\
                           </div>\
                           <div class="layui-form-item">\
                             <label class="layui-form-label"><span style="color: red">*</span>主页模板名称</label>\
                            <div class="layui-input-block">\
                               <input type="text" name="filename" lay-verify="title" autocomplete="off" placeholder="请输入主页模板名称" class="layui-input">\
                             </div>\
                           </div>\
                            <div class="layui-form-item">\
                             <label class="layui-form-label"><span style="color: red">*</span>项目文件夹名称</label>\
                             <div class="layui-input-block">\
                               <input type="text" name="projectname" lay-verify="title" autocomplete="off" placeholder="请输入项目文件夹名称" class="layui-input">\
                             </div>\
                           </div>\
                       </form>\
              \
               ';


        layui.use('form', function(){
            var form = layui.form;
            var treeSelect= layui.treeSelect;

            //监听提交
            layer.open({
                type: 1,
                title: '新增栏目',
                content: addHtml,
                area:['500px','450px'],
                btn: ['提交', '取消'],

                success:function (){
                    form.render();//弹出层打开时重载表单，不然select会打不开
                }, yes:function (layIndex) {
                    $('#form1').ajaxSubmit({
                        success: function (rsp) {
                            rsp=$.parseJSON(rsp)
                            if (rsp['code']>0){
                                layer.msg('配置添加成功');
                                setTimeout(function() {
                                    layer.close(layIndex);//延迟1秒关闭弹窗
                                    location.reload(true)//页面刷新
                                }, 1000);
                            }else {
                                layer.msg(rsp['message'])
                            }

                        }
                    });
                }

            });

        });



    }





    //监听行工具事件
    table.on('tool(test)', function(obj){
        var data = obj.data;

         if(obj.event === 'edit'){
            //修改文章

           editConfig(data);

        }
    });
});




function editConfig(data){

    var addHtml = '<form id="form1" class="layui-form" method="post" action="{:url(\'admin/home/editConfig\')}" style="width:460px; margin-top: 20px;">\
                           <div class="layui-form-item">\
                             <label class="layui-form-label"><span style="color: red">*</span>项目路径</label>\
                             <div class="layui-input-block">\
                             \ <input type="hidden" name="id" lay-verify="title" value="'+data.id+'" class="layui-input">\
                               <input type="text" name="path" lay-verify="title" autocomplete="off" placeholder="请输入项目路径" value="'+data.homepath+'" class="layui-input">\
                             </div>\
                           </div>\
                           <div class="layui-form-item">\
                             <label class="layui-form-label"><span style="color: red">*</span>主页模板名称</label>\
                            <div class="layui-input-block">\
                               <input type="text" name="filename" lay-verify="title" autocomplete="off" placeholder="请输入主页模板名称" value="'+data.filename+'" class="layui-input">\
                             </div>\
                           </div>\
                            <div class="layui-form-item">\
                             <label class="layui-form-label"><span style="color: red">*</span>项目文件夹名称</label>\
                             <div class="layui-input-block">\
                               <input type="text" name="projectname" lay-verify="title" autocomplete="off" placeholder="请输入项目文件夹名称" value="'+data.projectname+'" class="layui-input">\
                             </div>\
                           </div>\
                       </form>\
              \
               ';


    layui.use('form', function(){
        var form = layui.form;
        var treeSelect= layui.treeSelect;

        //监听提交
        layer.open({
            type: 1,
            title: '新增栏目',
            content: addHtml,
            area:['500px','450px'],
            btn: ['提交', '取消'],

            success:function (){
                form.render();//弹出层打开时重载表单，不然select会打不开
            }, yes:function (layIndex) {
                $('#form1').ajaxSubmit({
                    success: function (rsp) {
                        rsp=$.parseJSON(rsp)
                        if (rsp['code']>0){
                            layer.msg('配置修改成功');
                            setTimeout(function() {
                                layer.close(layIndex);//延迟1秒关闭弹窗
                                location.reload(true)//页面刷新
                            }, 1000);
                        }else {
                            layer.msg(rsp['message'])
                        }

                    }
                });
            }

        });

    });



}
</script>


{/block}